<?php require_once 'config.php';?>
<?php require_once 'function.php';?>
<?php $get = $_GET?>
<?php $data_error = false?>
<?php if($get['type'] == 'ykyun') $get['type'] = 'youku_ac';?>
<?php $auto_play = (!$config['auto_play']? '' : 'autoplay="autoplay"');?>
<?php $config['referer_msg'] = empty($config['referer_msg'])? "您的请求被拒绝。" : $config['referer_msg'];?>
<?php $config['play_title']  = empty($config['play_title'])? "PlayM3u8视频解析平台在线播放" : $config['play_title'];?>
<?php $refs = isset($_SERVER['HTTP_REFERER']) ? addslashes($_SERVER['HTTP_REFERER']) : current_url();?>
<?php $refs = empty($config['qrcode_url'])? $refs : $config['qrcode_url'];?>
<?php $get['refresh'] = empty($get['refresh'])? 1 : $get['refresh'] + 1;?>
<?php $data = !empty($get['url'])? authcode($get['url'],'DECODE',$config['data_key']) : authcode($get['vid'],'DECODE',$config['data_key']);
if(!empty($data)){
    if(substr($data,0,4) == 'http') {
		$get['url'] = $data;
	} else {
		$get['vid'] = $data;
	}
}?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
 <head> 
  <meta name="description" content="PlayM3u8 云解析平台 http://www.playm3u8.com">
  <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" /> 
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
  <link rel="shortcut icon" href="extend/playm3u8.png">
  <title><?php echo $config['play_title']?></title> 
  <style type="text/css">body,html,div{background-color:#000;padding: 0;margin: 0;width:100%;height:100%;color:#aaa;}</style> 
  <script type="text/javascript">
    var definition = "<?php echo $config['definition']?>";
    var qrcode = "<?php echo $config['qrcode']?>";
    var prompttext = "<?php echo $config['prompttext']?>";
	var playm3u8_logo = "<?php echo $config['playm3u8_logo']?>";
	var pm_logo = "<?php echo $config['pm_logo']?>";
  </script>
  <script type="text/javascript" src="extend/js/crypto-js/rollups/aes.js" charset="utf-8"></script>
  <script type="text/javascript" src="extend/js/crypto-js/components/pad-zeropadding.js" charset="utf-8"></script>
  <script type="text/javascript" src="extend/js/jquery.min.js"></script> 
  <script type="text/javascript" src="ckplayer/ckplayer.js" charset="utf-8"></script>
 </head> 
 <body style="overflow-y:hidden;"> 
  <div id="loading" style="font-weight:bold;padding-top:120px;" align="center">
	<?php echo $config['start_msg']?>
  </div> 
  <div id="a1" style="display:none;"></div> 
  <div id="error" style="display:none;font-weight:bold;padding-top:120px;" align="center"></div> 
  <script type="text/javascript">
    var load = false;
	var refresh = "<?php echo $get['refresh']?>"
    var isiPad = navigator.userAgent.match(/iPad|iPhone|Android|Linux|iPod/i) != null;
	function player(){
		$.post("playm3u8.php", {"data": get("<?php echo authcode(merge_string($get),'JM')?>")},
		function(data){
			if(data['code'] == 200){
				if(data['ext']=='iframe'){
					$('#a1').html('<iframe width="100%" height="100%" allowTransparency="true" frameborder="0" scrolling="no" src="'+data['url']+'"></iframe>');
				}else if(data['ext']=='h5'){
					$('#a1').html('<video id="vod" src="'+data['url']+'" controls="controls" <?php echo $auto_play?> width="100%" height="100%"></video>');
				}else if(data['ext'] == 'xml'){
					var flashvars = {
						f: data['url'],
						s: 2,
						p: "<?php echo $config['auto_play']?>",
						c: 0,
						e: 5,
						my_url:'<?php echo utf8encode($refs)?>',
						m: "<?php echo $config['ad_m']?>",
						d: "<?php echo $config['ad_d']?>",
						u: "<?php echo $config['ad_u']?>",
						l: "<?php echo $config['ad_l']?>",
						r: "<?php echo $config['ad_r']?>",
						t: "<?php echo $config['ad_t']?>",
						my_title: "<?php echo empty($get['play_title'])? 'PlayM3u8 云解析平台-正在播放' : $get['play_title']?>"
					};
					var params = {bgcolor: '#FFF',allowFullScreen: true,allowScriptAccess: 'always',wmode: 'transparent'};
					CKobject.embedSWF('ckplayer/ckplayer.swf', 'a1', 'ckplayer_a1', '100%', '100%', flashvars, params);
				}
				$('#loading').hide();
				$('#a1').show();
			}else{
                // 请求失败将会无刷新重新加载一次
                if(load == false){
                    load = true;
                    player();
                } else {
                   message(data['msg']);
                }
			}
		},"json");
	}
	if("<?php echo auth_referer()?>" == ""){
		if("<?php echo $data_error?>" == ""){
			player();
		} else {
			message("<?php echo $config['referer_msg'];?>");
		}
	} else {
		if("<?php echo $config['referer_url']?>" == ""){
			message("<?php echo $config['referer_msg'];?>");
		} else {
			window.location.href = "<?php echo $config['referer_url']?>";
		}
	}
	function message(msg){
		$('#loading').hide();
		$('#a1').hide();
		$('#error').show();
		$('#error').html(msg);
	}
</script>
  <?php
  if(!empty($config['script_str'])) {
	  $jsfile = explode('|',$config['script_str']);
	  foreach ($jsfile as $v) {
		  if (is_file($v)) {
			  echo '<script type="text/javascript" src="'.$v.'" charset="utf-8"></script>'."\n";
		  }
	  }
  }?>
 </body>
</html>